﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
   public class TrangThaiPhongDAO
    {
       public List<TrangThaiPhongDTO> DanhSachTrangThaiPhong()
       {
           List<TrangThaiPhongDTO> kq = new List<TrangThaiPhongDTO>();
           string str = "select*from TrangThaiPhong";
           DataProvider dp = new DataProvider();
           dp.Connect();
           SqlDataReader dr = dp.ExecuteQuery(str);
           if (dr.HasRows)
           {
               while (dr.Read())
               {
                   TrangThaiPhongDTO ttp = new TrangThaiPhongDTO();
                   ttp.MaTrangThai = int.Parse(dr["MaTrangThai"].ToString());
                   ttp.TenTrangThai = dr["TenTrangThai"].ToString();
                   kq.Add(ttp);
               }
           }
           return kq;
       }
       public TrangThaiPhongDTO LayTrangThaiPhongByMaTrangThaiPhong(int maTrangThaiPhong)
       {
           TrangThaiPhongDTO ttp = new TrangThaiPhongDTO();
           string str = "select*from TrangThaiPhong where MaTrangThaiPhong=" + maTrangThaiPhong;
           DataProvider dp = new DataProvider();
           dp.Connect();
           SqlDataReader dr = dp.ExecuteQuery(str);
           dr.Read();
           ttp.MaTrangThai = int.Parse(dr["MaTrangThai"].ToString());
           ttp.TenTrangThai = dr["TenTrangThai"].ToString();
           dp.Disconnect();
           return ttp;
       }
       public Boolean ThemTrangThaiPhong(TrangThaiPhongDTO ttp)
       {
           Boolean kq = false;
           string str = "insert into TrangThaiPhong(MaTrangThai,TenTrangThai) values('"+ttp.MaTrangThai+"','"+ttp.TenTrangThai+"')";
           DataProvider dp = new DataProvider();
           dp.Connect();
           int i = dp.ExecuteNonQuery(str);
           if (i != 0)
               kq = true;
           return kq;
       }
       public Boolean CapNhatTrangThaiPhong(TrangThaiPhongDTO ttp)
       {
           Boolean kq = false;
           string str = "update TrangThaiPhong set TenTrangThai='"+ttp.TenTrangThai+"' where MaTrangThai='"+ttp.MaTrangThai+"'";
           DataProvider dp = new DataProvider();
           dp.Connect();
           int i = dp.ExecuteNonQuery(str);
           if (i != 0)
               kq = true;
           return kq;
       }
       public Boolean XoaTrangThaiPhong(int maTrangThaiPhong)
       {
           Boolean kq = false;
           string str = "delete from TrangThaiPhong where MaTrangThaiPhong="+maTrangThaiPhong;
           DataProvider dp = new DataProvider();
           dp.Connect();
           int i = dp.ExecuteNonQuery(str);
           if (i != 0)
               kq = true;
           return kq;
       }
    }
}
